import request from '../utils/request'
// 登录请求
export const login = data => {
  return request({
    url: 'login',
    method: 'POST',
    data
  })
}
// 获取左侧边导航栏
export const getMenus = () => {
  return request({
    url: 'menus',
    method: 'GET'
  })
}

/**
 * 获取用户数据列表
 * @param {*} params {query pagenum pagesize}
 * @returns promise
 */
export const getUsersList = params => {
  return request({
    url: 'users',
    method: 'GET',
    params
  })
}

/**
 * 添加用户
 * @param {*} data {username,password,email,mobile}
 * @returns promise
 */
export const addUser = data => {
  return request({
    url: 'users',
    method: 'POST',
    data
  })
}

/**
 * 修改用户状态
 * @param {*} uId 用户 ID
 * @param {*} type 用户状态 值为 true 或者 false
 * @returns promise
 */
export const getNewStatus = (uId, type) => {
  return request({
    url: 'users/' + uId + '/state/' + type,
    method: 'PUT'
  })
}

/**
 * 根据id查询用户信息
 * @param {*} id 用户id
 * @returns promise
 */
export const queryUSerInfo = id => {
  return request({
    url: 'users/' + id,
    method: 'GET'
  })
}

/**
 * 更新用户提交
 * @param {*} id 用户id
 * @returns promise
 */
export const editUSerInfo = (id, data) => {
  return request({
    url: 'users/' + id,
    method: 'PUT',
    data
  })
}

/**
 * 删除用户
 * @param {*} id 用户id
 * @returns promise
 */
export const deleteUSer = (id) => {
  return request({
    url: 'users/' + id,
    method: 'DELETE'
  })
}

/**
 * 分配用户角色
 * @param {*} id 用户
 * @param {*} rid 角色rid
 * @returns promise
 */
export const assignUserRole = (rid, id) => {
  return request({
    url: 'users/' + id + '/role',
    method: 'PUT',
    data: {
      rid
    }
  })
}

/**
 * 请求角色列表
 * @returns promise
 */
export const userRoleList = () => {
  return request({
    url: 'roles',
    method: 'GET'
  })
}
